// pages/msgNotify/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage: 1,
    loadingMoreHidden: 1,
    msgList: []
  },

  getMsgList: function(){
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Staff/GetMsgList?uid=' + app.globalData.userInfo.Uid + '&page=' + that.data.CurrentPage,
      success: function(res){
        if(res.data.Code == 0){
          let list = res.data.Data.Items;
          if (!list) {
            return;
          }
          if (that.data.CurrentPage != 1) {
            var preGoods = that.data.msgList;
            list = preGoods.concat(list);
          }
          that.setData({
            msgList: list,
            loadingMoreHidden: res.data.Data.TotalPages
          })
        }else{
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },

  // 加载更多
  loadMore: function (e) {
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden) {
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.getMsgList();
    } else {
      return
    }
  },

  toDetails: function(e){
    let url = e.currentTarget.dataset.url;
    if (url){
      wx.navigateTo({
        url: '/' + e.currentTarget.dataset.url,
      })
    }
  },

  onReachBottom: function() {
    this.loadMore()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMsgList();
  }

})